home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Utilities / Winter Shell 1.0d2 / Source / Libraries / ChooserLib / ChooserLib.c next >
Encoding:
C/C++ Source or Header  |  1993-03-22  |  2.0 KB  |  80 lines  |  [TEXT/KAHL]

  1. /*    
  2.     Functions for getting and setting the name maintained by the Chooser
  3.     Desk Accessory. Getting this name relies on the undocumented feature
  4.     that the name is stored in a 'STR ' resource in the System file.
  5.     
  6.     Revision History:
  7.     
  8.     91/04/23 AIH
  9.     - When setting the chooser name there's no need to set the resource file
  10.     to the system resource file
  11.     
  12.     91/04/21 AIH
  13.     - Shortened string parameters to their maximum length of 31 characters
  14.     
  15.     91/03/11 AIH
  16.     - Removed unused functions for modifying the 'DITL' resource of the
  17.     Chooser, since they don't work with new (v7.0) system software
  18.     
  19.     91/01/21 AIH
  20.     - Added brief comment describing purpose of this file
  21.     
  22.     91/01/05 Ari Halberstadt
  23.     - Inserted this standard header in all files */
  24.  
  25. #include <string.h>
  26. #include "MemoryLib.h"
  27. #include "StringLib.h"
  28. #include "ResourceLib.h"
  29. #include "ChooserLib.h"
  30.  
  31. #define CHOOSER_NAME_LEN        (32)        /* maximum length of a chooser name */
  32. #define STR_CHOOSER_NAME_ID    (-16096)    /* system resource containing chooser name */
  33.  
  34. /* get the current chooser name */
  35. OSErr ChooserNameGet(CStr31 name)
  36. {
  37. BEGIN
  38.     return(ResString31(STR_CHOOSER_NAME_ID, name));
  39. END
  40. }
  41.  
  42. /* set the current chooser name */
  43. OSErr ChooserNameSet(CStr31 the_name)
  44. {
  45. BEGIN
  46.     short oldref;                        /* original resource file */
  47.     char name[CHOOSER_NAME_LEN];    /* truncated name */
  48.     Handle rsrc;                        /* the chooser name resource */
  49.     OSErr err = noErr;
  50.     
  51.     require(StrValid(name, sizeof(CStr31)));
  52.  
  53.     /* truncate name to the maximum length */
  54.     strncpy(name, the_name, CHOOSER_NAME_LEN-1);
  55.     name[CHOOSER_NAME_LEN-1] = 0;
  56.     
  57.     /* use system resource file */
  58.     oldref = CurResFile();
  59.     UseResFile(0);
  60.     
  61.     /* get handle to chooser name resource */
  62.     err = ResGet(&rsrc, 'STR ', STR_CHOOSER_NAME_ID);
  63.     if (! err) {
  64.     
  65.         /* un-protect the chooser name resource */
  66.         err = ResAttributeSet(rsrc, resProtected, false);
  67.         if (! err) {
  68.         
  69.             /* set the chooser name resource */
  70.             err = ResStringSet(STR_CHOOSER_NAME_ID, name);
  71.         }
  72.     }
  73.  
  74.     /* restore resource file */
  75.     UseResFile(oldref);
  76.     
  77.     return(err);
  78. END
  79. }
  80.